﻿using UnityEngine;
using System.Collections;

public class lqf_camera : MonoBehaviour {
    public float xMargin = 1.0f;
    public float yMargin = 1.0f;
    public float xSooth = 1;
    public float ySooth = 1;
    //public float maxXAndY = -50;
    //public float minXAndY = -50;

    public GameObject obj;
	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {
        
	}


    bool CheckX()
    {
        return Mathf.Abs(transform.position.x - obj.transform.position.x) > xMargin;
    }

    bool CheckY()
    {
        return Mathf.Abs(transform.position.y - obj.transform.position.y) > yMargin;
    }

    void FixedUpdate()
    {
        Player();
    }

    void Player()
    {
        float targetX = transform.position.x;
        float targetY = transform.position.y;
        if (CheckX())
        {
            targetX = Mathf.Lerp(transform.position.x, obj.transform.position.x, 8 * Time.deltaTime);
        }

        if (CheckY())
        {
            targetY = Mathf.Lerp(transform.position.y, obj.transform.position.y, 8 * Time.deltaTime);
        }
        //targetX = Mathf.Clamp(targetX, minXAndY, maxXAndY);
        //targetY = Mathf.Clamp(targetY, minXAndY, maxXAndY);
        transform.position = new Vector3(targetX, targetY, transform.position.z);
    }
}
